# -*- coding: utf-8 -*-
import cv2
import sys
import math
# 手机软件名：ip摄像头
# 根据摄像头设置IP及rtsp端口
url = 'http://192.168.137.170:8081/video'

# 读取视频流
cap = cv2.VideoCapture(url)
# 设置视频参数
cap.set(3, 480)

print(cap.isOpened())

print(sys.version)

print(cv2.__version__)

while cap.isOpened():
    ret_flag, img_camera = cap.read()
    cv2.imshow("camera", img_camera)

    # 每帧数据延时 1ms, 延时为0, 读取的是静态帧
    while (True):
        # Capture frame-by-frame
        ret, frame = cap.read()

        # Our operations on the frame come here
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        xmlfile = r'D:\Sheji\PYcharm\APP\pythonProject9\haarcascade_frontalface_default.xml'

        face_cascade = cv2.CascadeClassifier(xmlfile)

        faces = face_cascade.detectMultiScale(
            gray,
            scaleFactor=1.15,
            minNeighbors=5,
            minSize=(5, 5),
        )
        print("有{0}个人!".format(len(faces)))
        for (x, y, w, h) in faces:
            cv2.rectangle(frame, (x, y), (x + w, y + w), (0, 255, 0), 2)

        cv2.imshow("frame", frame)
        # Display the resulting frame
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
# 释放所有摄像头
cap.release()

# 删除窗口
cv2.destroyAllWindows()



# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()


